Skip to main content

std.array

Pebble 0.3.1 · all symbols on this page are stable.

Polymorphic helpers over Array<T> — the native, random-access variant of a list. Unlike List<T>, Array<T> supports O(1) indexed access via at.

Use std.array.fromList to convert a List<T> once and then index into the result repeatedly.

Methods

FunctionDescription
length<T>(xs: Array<T>): intNumber of elements.
at<T>(xs: Array<T>, i: int): TElement at index i. Fails on out-of-bounds.
fromList<T>(xs: List<T>): Array<T>Convert a List<T> to an Array<T>. O(n).

Examples

using { length, at, fromList } = std.array;

const xs: Array<int> = fromList([10, 20, 30]); // 3-element array
const n: int = length(xs); // 3
const v: int = at(xs, 1); // 20

See also

  • Array<T> — method-call surface (xs.at(i), xs.length())
  • std.list — most transformations live on List<T>; convert with fromList when you need random access